/**
 * JDBC各种操作
 * @author 董一华
 * @since 1.00
 * @version 1.00 
 * 
 * 修订列表： v1.00 2009-10-24 
 * 			修订人：董一华 
 * 			修订内容：初始版本 
 */

package com.zjht.gmcc.bean.util;

import java.sql.Connection;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class JDBCUtil {

	private static DataSource ds;

	/**
	 * 获取DataSource
	 * @author dyh 2009-11-28
	 */
	public static DataSource getDataSource() {
		if (ds == null) {
			try {
				Context ic = new InitialContext();
				ds = (DataSource) ic.lookup("java:comp/env/jdbc/oracle_jndi");

			} catch (Exception ex) {
			}
		}
		return ds;
	}

	/**
	 * 是否已连接数据库
	 * @author dyh 2009-11-28
	 */
	public static boolean isConnected(Connection conn) throws Exception {
		return (conn != null && !conn.isClosed());
	}

	/**
	 * 关闭连接
	 * @author dyh 2009-11-28
	 */
	public static void CloseConnection(Connection conn) {
		try {
			if (conn != null && !conn.isClosed()) {
				conn.close();
			}
		} catch (Exception x) {

		} finally {
			conn = null;
		}
	}
}
